#!/bin/sh

# Copyright (C) 2012-2020 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Checks that the initLogger() call uses for unit tests respects the setting of
# the buffer value

# Exit with error if commands exit with non-zero and if undefined variables are
# used.
set -eu

# Include common test library.
# shellcheck disable=SC1091
# SC1091: Not following: ... was not specified as input (see shellcheck -x).
. "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"

tempfile="@abs_builddir@/buffer_logger_test_tempfile_$$"

printf 'Checking that buffer initialization works:\n'

test_start 'buffer-logger.buffer-including-process()-call'
cat > $tempfile << .
INFO  [buffertest.log] LOG_BAD_SEVERITY unrecognized log severity: info
INFO  [buffertest.log] LOG_BAD_SEVERITY unrecognized log severity: info
.
./buffer_logger_test 2>&1 | \
    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\.\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
    cut -d' ' -f3- | diff $tempfile -
test_finish 0

test_start 'buffer-logger.buffer-excluding-process()-call'
cat > $tempfile << .
INFO [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
DEBUG [buffertest.log]: LOG_BAD_DESTINATION unrecognized log destination: debug-50
INFO [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
.
./buffer_logger_test -n 2>&1 | diff $tempfile -
test_finish 0

# Tidy up.
rm -f $tempfile
